
package com.hlkj.pay.gateway.order.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.extension.executor.ExtensionExecutor;
import com.hlkj.framework.extension.scenario.BizScenario;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantComplaintExtPt;
import com.hlkj.pay.app.merchant.ext.dto.order.ChannelComplaintOrderContext;
import com.hlkj.pay.app.merchant.ext.impl.wxpay.dto.WxComplaintHistoryDto;
import com.hlkj.pay.dto.order.notify.OrderComplaintNotifyDto;
import com.hlkj.pay.gateway.order.IChannelComplaintGateway;
import com.hlkj.pay.infrastructure.model.order.OrderComplaintDO;
import com.hlkj.pay.service.merchant.IMerchantApplicationService;
import com.hlkj.pay.service.pay.IProviderService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2025/02/10 14:38
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ChannelComplaintGatewayImpl implements IChannelComplaintGateway {

    private final ExtensionExecutor extensionExecutor;

    private final IMerchantApplicationService merchantApplicationService;

    private final IProviderService providerService;

    @Override
    public boolean extensionExist(String channelCode) {
        return extensionExecutor.executeExist(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelCode));
    }

    @Override
    public CommonResult<List<OrderComplaintDO>> queryComplaintPage(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.queryComplaintPage(channelComplaintOrderContext));
    }


    @Override
    public CommonResult<OrderComplaintNotifyDto> complaintStatusParse(HttpServletRequest request, ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class,BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.complaintStatusParse(request, channelComplaintOrderContext));
    }

    @Override
    public  CommonResult<OrderComplaintNotifyDto> queryComplaintDetail(ChannelComplaintOrderContext channelComplaintOrderContext) {
         return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.queryComplaintDetail(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> query(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.queryComplaintNotify(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> saveComplaintNotifyUrl(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.saveComplaintNotify(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> replyUser(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.replyUser(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> complete(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.completeComplaint(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> refund(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.updateComplaintProgress(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<PageResult<WxComplaintHistoryDto>> queryHistoryPage(ChannelComplaintOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantComplaintExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.queryComplaintHistory(channelComplaintOrderContext));
    }

}
